package com.minxi.java.Dao.impl;

import com.minxi.java.Dao.base;
import com.minxi.java.JavaBean.UserInfo;

import java.sql.*;
import java.util.ArrayList;

public class ALL extends base {
    public ArrayList xianshi(){
        ArrayList<UserInfo> objects = new ArrayList<>();
        ResultSet selectsql =selectsql("SELECT aid,adate,start,end,price,type,cname FROM t_airline ai INNER JOIN t_company co ON ai.cid=co.cid;");
        try {
            while (selectsql.next()){00
                String id =selectsql.getString("aid");
                String date =selectsql.getString("adate");
                String start =selectsql.getString("start");
                String end =selectsql.getString("end");
                String price =selectsql.getString("price");
                String type =selectsql.getString("type");
                String cname =selectsql.getString("cname");
                objects.add(new UserInfo(id,date,start,end,Integer.parseInt(price),type,cname));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
            return objects;
    }
//    public static void main(String[] args) {
//        ALL all = new ALL();
//        ArrayList xianshi = all.xianshi();
//        System.out.println(xianshi.get(1));
//        System.out.println(xianshi.get(2));
//    }
    public void add(UserInfo a){
        String sql="INSERT INTO t_airline(adate,start,end,price,type,cid)VALUES(?,?,?,?,?,?)";
        PreparedStatement updatasql = updatasql(sql);
        try {
            updatasql.setObject(1,a.getAdate());
            updatasql.setObject(2,a.getStart());
            updatasql.setObject(3,a.getEnd());
            updatasql.setObject(4,a.getPrice());
            updatasql.setObject(5,a.getType());
            updatasql.setObject(6,a.getCid());
            updatasql.executeUpdate();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }




}
